import request from '@/utils/request.js'
import {getRefreshTokenAtStorage, getTokenAtStorage} from "@/utils/tokens.js";

/**
 * 注册、登录相关API
 */
export default {
    /**
     * 发送验证码
     */
    sendSmsCode: (contact) => {
        return new Promise((resolve, reject) => {
            resolve({
                ok: true,
                msg: "",
                data: null
            })
        });
    }
    /**
     * 验证验证码
     * @param code
     * @returns {Promise | Promise<unknown>}
     */
    , validSmsCode: (code) => {
        return new Promise((resolve, reject) => {
            resolve({
                ok: true,
                msg: "",
                data: null
            })
        });
    }

    /**注册*/
    , signUp: (data) => {
        return new Promise((resolve, reject) => {
            resolve({
                ok:true,
                msg: "",
                data: null
            })
        });
    }

    /**username登录*/
    , logIn: (username, password, code = "") => {
        console.debug(`>>> request login .. account=${username} ; password = ${password}`)
        return new Promise((resolve, reject) => {
            resolve({
                "code": 0,
                "msg": "",
                "data": {
                    "access_token": "eyJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJST0xFX1VTRVIiXSwiYXZhdGFyVXJsIjoiaHR0cDovLzEwMS40My4xMDIuMjE1OjkwMDAvZnJlZWNoYXQtcGljdHVyZS9ndWVzdF9hdmF0YXJfMTcwN2M2IiwidXNlcm5hbWUiOiJndWVzdCIsIm5pY2tuYW1lIjoiZ3Vlc3QiLCJzdGF0dXMiOjEsImp0aSI6ImNoaWRfZTMyMzFmNzM1YTNkIiwic3ViIjoiY2hpZF9lMzIzMWY3MzVhM2QiLCJpc3MiOiJhYmMiLCJpYXQiOjE3NDUxMzM2MDIsImV4cCI6MTc0NTIyMDAwMn0.KXCyCwimJiFTvJszpiFOblUHmAWkxhBOC3fBi01EvKI",
                    "refresh_token": "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJjaGlkX2UzMjMxZjczNWEzZCIsInN1YiI6Imd1ZXN0IiwiaXNzIjoiYWJjIiwiaWF0IjoxNzQ1MTMzNjAyLCJleHAiOjE3NDU1NjU2MDJ9.XG_VxnSCa9STBqYzxm1QvVm_8VO9TiGN6-SN8C6h75Y",
                    "userInfo": {
                        "id": "chid_e3231f735a3d",
                        "username": "guest",
                        "nickname": "guest",
                        "avatarUrl": "http://101.43.102.215:9000/freechat-picture/guest_avatar_1707c6",
                        "status": 1,
                        "authorities": [
                            {
                                "authority": "ROLE_USER"
                            }
                        ],
                        "accountNonLocked": true,
                        "accountNonExpired": true,
                        "credentialsNonExpired": true,
                        "enabled": true
                    }
                },
                "ok": true
            })
        });
    }
    /**退出登录 */
    , logOut: () => {
        return new Promise((resolve, reject) => {
            resolve({
                ok: true,
                msg: "",
                data: null
            })
        });
    }

    , verifyAuth:() =>{
        return new Promise((resolve, reject) => {
            resolve({
                ok: false,
                msg: "token已失效",
            })
        });
    }

    /**登录用户信息*/
    , getUserInfo: () => {
        return new Promise((resolve, reject) => {
            resolve({
                ok: true,
                msg: "",
                data: {
                    id: 110001,
                    username: 'guest',
                    nickname: 'guest',
                    avatarUrl: "",
                    roles: []
                }
            })
        });
    },

    /**
     * 更改密码
     * @param id
     * @param params
     * @returns {Promise | Promise<unknown>}
     */
    editPassword: (id, params) => {
        return new Promise((resolve, reject) => {
            resolve({
                ok: true,
                msg: "",
                data: null
            })
        });
    },
    /**
     * 更改头像
     * @param username
     * @param params
     * @returns {Promise<unknown>}
     */
    editAvatarUrl: (username, params) => {
        return new Promise((resolve, reject) => {
            resolve({
                ok: true,
                msg: "",
                data: null
            })
        });
    },
    /**
     * 更换手机号
     * @param id
     * @param params
     * @returns {Promise | Promise<unknown>}
     */
    editPhone: (id, params) => {
        return new Promise((resolve, reject) => {
            resolve({
                ok: true,
                msg: "",
                data: null
            })
        });
    },
    /**
     * 更换邮箱号
     * @param id
     * @param params
     * @returns {Promise | Promise<unknown>}
     */
    editEmail: (id, params) => {
        return new Promise((resolve, reject) => {
            resolve({
                ok: true,
                msg: "",
                data: null
            })
        });
    },
    /**
     * 更改个性签名
     * @param id
     * @param params
     * @returns {Promise | Promise<unknown>}
     */
    editProfile: (id, params) => {
        return new Promise((resolve, reject) => {
            resolve({
                ok: true,
                msg: "",
                data: null
            })
        });
    }

}
